#include <iostream>
#include <vector>
#include <stdexcept>
// g++ -std=c++11 vec_st.cc -o vec_st
int main() {
    size_t size = 1; // 初始大小 (单位: int 个数)
    std::vector<int> vec;

    try {
        std::cout << "Testing std::vector memory allocation...\n";

        while (true) {
            vec.reserve(size); // 预分配容量
            std::cout << "Successfully reserved vector of size: " 
                      << size << " ints (" 
                      << (size * sizeof(int)) / (1024.0 * 1024.0 * 1024.0) 
                      << " GB)\n";

            size *= 2; // 每次翻倍
        }
    } catch (const std::bad_alloc &e) {
        std::cerr << "Memory allocation failed at size: " 
                  << size << " ints (" 
                  << (size * sizeof(int)) / (1024.0 * 1024.0 * 1024.0) 
                  << " GB)\n";
    }

    return 0;
}
